<?php
// +----------------------------------------------------------------------
// | Crawler [ plugin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
// plugin command
namespace plugins\crawler\command; 

use think\console\Command;

use think\console\input\Argument;
use think\console\input\Option;

use think\console\Input;
use think\console\Output;

use plugins\crawler\service\CrawlerServiceFactory;

class Crawler extends Command
{
    protected function configure()
    {
        //argument
        //$this->addArgument('test', Argument::REQUIRED);
        //option
        $this->addOption('site', 's', Option::VALUE_OPTIONAL, 'fenxiangdashi'); //选项值选填

        $this->setName('crawler')->setDescription('grap data from other site');
    }
    /**
     * 定时执行命令 采集数据
     * @access public
     * @param  Input $input 
     * @param  Output $output 
     * @return void
     */
    protected function execute(Input $input, Output $output)
    {    
        $commandOptions = $input->getOptions();
        
        $crawlerService = CrawlerServiceFactory::create($commandOptions['site']);

        $crawlerService->input = $input;
        $crawlerService->output = $output;

        $crawlerService->start();
    }

}
